package mspdt.ubzuuch.mn;

import java.util.ArrayList;
import android.app.Activity;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListAdapter extends ArrayAdapter<String> {
	private final Activity context;
	private final ArrayList<String> names;
	private final ArrayList<String> desc;
	private final ArrayList<String> prices;
	private final ArrayList<String> images;
	private  ImageLoader imageLoader; 
	
	public ListAdapter(Activity context, ArrayList<String> names, ArrayList<String> desc, ArrayList<String> prices, ArrayList<String> images) {
		super(context, R.layout.list_body, names);
		this.context = context;
		this.names = names;
		this.desc = desc;
		this.prices=prices;
		this.images=images;
		imageLoader=new ImageLoader(context.getApplicationContext());
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if(convertView==null)
		{
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.list_body, null);
		}
		
		TextView tv_name = (TextView)convertView.findViewById(R.id.list_name);
		TextView tv_desc = (TextView)convertView.findViewById(R.id.list_desc);
		TextView tv_price = (TextView)convertView.findViewById(R.id.list_price);
		ImageView image = (ImageView)convertView.findViewById(R.id.list_image);
		tv_name.setText(Html.fromHtml(names.get(position)));
		tv_desc.setText(Html.fromHtml(desc.get(position)));
		tv_price.setText(Html.fromHtml(prices.get(position)));
		imageLoader.DisplayImage(images.get(position), image);
		return convertView;
	}
}